﻿-- Drop it all...
if object_id('dbo.FormatString0', 'FS') is not null drop function dbo.FormatString0;
if object_id('dbo.FormatString1', 'FS') is not null drop function dbo.FormatString1;
if object_id('dbo.FormatString2', 'FS') is not null drop function dbo.FormatString2;
if object_id('dbo.FormatString3', 'FS') is not null drop function dbo.FormatString3;
if object_id('dbo.FormatStringMax0', 'FS') is not null drop function dbo.FormatStringMax0;
if object_id('dbo.FormatStringMax1', 'FS') is not null drop function dbo.FormatStringMax1;
if object_id('dbo.FormatStringMax2', 'FS') is not null drop function dbo.FormatStringMax2;
if object_id('dbo.FormatStringMax3', 'FS') is not null drop function dbo.FormatStringMax3;
if exists (select * from sys.assemblies where name = N'Fotia.SqlClr') drop assembly [Fotia.SqlClr];
go

-- Create from scratch...
create assembly [Fotia.SqlClr] authorization dbo
from 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300F6B11D4A0000000000000000E00002210B0108000012000000060000000000008E3000000020000000400000000040000020000000020000040000000000000004000000000000000080000000020000000000000300408500001000001000000000100000100000000000001000000000000000000000003430000057000000004000002803000000000000000000000000000000000000006000000C000000B02F00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E7465787400000094100000002000000012000000020000000000000000000000000000200000602E7273726300000028030000004000000004000000140000000000000000000000000000400000402E72656C6F6300000C000000006000000002000000180000000000000000000000000000400000420000000000000000000000000000000070300000000000004800000002000500FC230000B40B000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001330040032000000010000110F00281000000A2D230F00281100000A178D010000010A061603A2062805000006281200000A281300000A2A7E1400000A2A00001330040036000000010000110F00281000000A2D270F00281100000A188D010000010A061603A2061704A2062805000006281200000A281300000A2A7E1400000A2A0000133004003A000000010000110F00281000000A2D2B0F00281100000A198D010000010A061603A2061704A2061805A2062805000006281200000A281300000A2A7E1400000A2A0000133004003F000000010000110F00281000000A2D300F00281100000A1A8D010000010A061603A2061704A2061805A206190E04A2062805000006281200000A281300000A2A7E1400000A2A4E0214FE0606000006731500000A280100002B2A00133001007E010000020000110275160000010A062C08066F1700000A2C02142A0275020000012C0F02A5020000010B1201281100000A2A0275170000012C1402A5170000010C1202281800000A8C180000012A0275190000012C1402A5190000010D1203281900000A8C1A0000012A02751B0000012C1502A51B00000113041204281A00000A8C1C0000012A02751D0000012C1502A51D00000113051205281B00000A8C1E0000012A02751F0000012C1502A51F00000113061206281C00000A8C200000012A0275210000012C1502A52100000113071207281D00000A8C220000012A0275230000012C1502A52300000113081208281E00000A8C240000012A0275250000012C1502A52500000113091209281F00000A8C240000012A0275260000012C1502A526000001130A120A282000000A8C270000012A0275280000012C1502A528000001130B120B282100000A8C290000012A02752A0000012C1502A52A000001130C120C282200000A8C2B0000012A02752C0000012C0C02742C0000016F2300000A2A022A1E02282400000A2A9E0F00281000000A2D180F00281100000A038C02000001282500000A281300000A2A7E1400000A2AB60F00281000000A2D1E0F00281100000A038C02000001048C02000001282600000A281300000A2A7E1400000A2ACE0F00281000000A2D240F00281100000A038C02000001048C02000001058C02000001282700000A281300000A2A7E1400000A2A133004004E000000010000110F00281000000A2D3F0F00281100000A1A8D010000010A0616038C02000001A20617048C02000001A20618058C02000001A206190E048C02000001A206281200000A281300000A2A7E1400000A2A1E02282400000A2A000042534A4201000100000000000C00000076322E302E35303732370000000005006C0000008C040000237E0000F80400007004000023537472696E67730000000068090000080000002355530070090000100000002347554944000000800900003402000023426C6F620000000000000002000001471502080908000000FA013300160000010000002C000000030000000C0000001E0000002700000014000000020000000100000001000000020000000100000000000A00010000000000060055004E000A007D006800060056014E0006007C016A01060093016A010600B0016A010600CF016A010600E8016A01060001026A0106001C026A01060037026A0106006F025002060083026A010600AF029C023B00C30200000600F202D20206001203D2020A004B033003060075034E00060094034E000600A0034E000A00B10368000A00BB0368000600C4034E000A00CA0368000600D3034E000A00D90368000600E2034E000A00E80368000600F2034E000A00F9036800060003044E000A000A046800060016044E000A001F046800060028044E000A00300468000A003B046800060046044E000A004E046800060056044E000A005B046800060063044E000A00680468000000000001000000000001000100010010001B0028000500010001000100100035002800050001000800502000000000960087000A0001009020000000009600950012000300D420000000009600A3001B0006001C21000000009600B10025000A006721000000009100BF0030000F007C21000000009100D000370010000623000000008618E8003C0011000E23000000009600EE00400011003623000000009600FF004900130064230000000096001001540016009823000000009600210161001A00F223000000008618E8003C001F00000001003201000002003901000001003201000002003901000003003E01000001003201000002003901000003003E01000004004301000001003201000002003901000003003E01000004004301000005004801000001004D01000001004D01000001003201000002003901000001003201000002003901000003003E01000001003201000002003901000003003E01000004004301000001003201000002003901000003003E010000040043010000050048011900E8003C002100E80075002900E80075003100E80075003900E80075004100E80075004900E80075005100E80075005900E80075006100E8007A006900E80075007100E8007F008100E80085008900E8003C009100E8003C00110060032E0111006B03320199007C033601110083033D0111008F0343010C00E8005301A900A6035901B10060032E01B9006B037001C9006B037401D9006B037801E9006B037C01F9006B03800109016B03840119016B038A0129016B038A0131016B032E0141016B03900151016B03940161016B0332010900E8003C0099007C03BD0199007C03C30199007C03CA0120007B008A002E001300D2012E001B00E4012E002300E4012E00730014022E003B00EA012E002B00E4012E003300D2012E005300E4012E006B000B022E004300E4012E006300020240007B008A0060007B008A0080007B008A0000017B008A0020017B008A0040017B008A0060017B008A00E4010B00700047019A014C0104800000010000000000000000000000000028000000020000000000000000000000010045000000000002000000000000000000000001005C00000000002D006B010000003C4D6F64756C653E00466F7469612E53716C436C722E646C6C00466F726D6174537472696E6700466F7469612E53716C436C7200466F726D6174537472696E674D6178006D73636F726C69620053797374656D004F626A6563740053797374656D2E446174610053797374656D2E446174612E53716C54797065730053716C537472696E6700466F726D6174537472696E673000466F726D6174537472696E673100466F726D6174537472696E673200466F726D6174537472696E67330053716C54797065546F4E65745479706500436F6E7665727453716C54797065546F4E657454797065002E63746F7200466F726D6174537472696E674D61783000466F726D6174537472696E674D61783100466F726D6174537472696E674D61783200466F726D6174537472696E674D61783300666F726D617400617267300061726731006172673200617267330073716C56616C756500506172616D41727261794174747269627574650053797374656D2E5265666C656374696F6E00417373656D626C795469746C6541747472696275746500417373656D626C794465736372697074696F6E41747472696275746500417373656D626C79436F6E66696775726174696F6E41747472696275746500417373656D626C79436F6D70616E7941747472696275746500417373656D626C7950726F6475637441747472696275746500417373656D626C79436F7079726967687441747472696275746500417373656D626C7954726164656D61726B41747472696275746500417373656D626C7943756C747572654174747269627574650053797374656D2E52756E74696D652E496E7465726F70536572766963657300436F6D56697369626C6541747472696275746500417373656D626C7956657273696F6E4174747269627574650053797374656D2E446961676E6F73746963730044656275676761626C6541747472696275746500446562756767696E674D6F6465730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465004D6963726F736F66742E53716C5365727665722E5365727665720053716C46756E6374696F6E417474726962757465006765745F49734E756C6C006765745F56616C756500537472696E6700466F726D6174006F705F496D706C69636974004E756C6C00436F6E766572746572603200417272617900436F6E76657274416C6C00494E756C6C61626C650053716C496E74313600496E7431360053716C496E74333200496E7433320053716C496E74363400496E7436340053716C53696E676C650053696E676C650053716C446F75626C6500446F75626C650053716C4461746554696D65004461746554696D650053716C4D6F6E657900446563696D616C0053716C446563696D616C0053716C426F6F6C65616E00426F6F6C65616E0053716C4279746500427974650053716C4775696400477569640053716C586D6C00000003200000000000D8AFF158FA86884188226C311D6CB5ED0008B77A5C561934E089070002110911091C080003110911091C1C090004110911091C1C1C0A0005110911091C1C1C1C0600011D1C1D1C0400011C1C032000010800021109110911090A000311091109110911090C0004110911091109110911090E00051109110911091109110911090401000000042001010E042001010205200101113D042001010880A2010002005455794D6963726F736F66742E53716C5365727665722E5365727665722E446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038390A446174614163636573730000000054020F497344657465726D696E697374696301032000020320000E0600020E0E1D1C05000111090E030611090407011D1C06151251021C1C052002011C18111002021D1E011D1E00151251021E001E01040A021C1C03200006032000080320000A0320000C0320000D052000118089052000118091032000050520001180AD22070D12591109115D1165116D1175117D11808511808D1180951180991180A11180A90500020E0E1C0600030E0E1C1C0700040E0E1C1C1C1101000C466F7469612E53716C436C72000005010000000017010012436F7079726967687420C2A920203230303900000801000200000000000801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F7773010000000000F6B11D4A000000000200000068000000CC2F0000CC110000525344532BA1626C060E87429C8EE5DD3960B22704000000443A5C56532053746173685C50726F6A656374735C466F7469612E53716C436C725C7372635C466F7469612E53716C436C725C6F626A5C52656C656173655C466F7469612E53716C436C722E706462005C30000000000000000000007E300000002000000000000000000000000000000000000000000000703000000000000000000000000000000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF25002040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001800008000000000000000000000000000000100010000003000008000000000000000000000000000000100000000004800000058400000D00200000000000000000000D00234000000560053005F00560045005200530049004F004E005F0049004E0046004F0000000000BD04EFFE00000100000001000000000000000100000000003F000000000000000400000002000000000000000000000000000000440000000100560061007200460069006C00650049006E0066006F00000000002400040000005400720061006E0073006C006100740069006F006E00000000000000B00430020000010053007400720069006E006700460069006C00650049006E0066006F0000000C020000010030003000300030003000340062003000000044000D000100460069006C0065004400650073006300720069007000740069006F006E000000000046006F007400690061002E00530071006C0043006C00720000000000300008000100460069006C006500560065007200730069006F006E000000000031002E0030002E0030002E003000000044001100010049006E007400650072006E0061006C004E0061006D006500000046006F007400690061002E00530071006C0043006C0072002E0064006C006C00000000004800120001004C006500670061006C0043006F007000790072006900670068007400000043006F0070007900720069006700680074002000A90020002000320030003000390000004C00110001004F0072006900670069006E0061006C00460069006C0065006E0061006D006500000046006F007400690061002E00530071006C0043006C0072002E0064006C006C00000000003C000D000100500072006F0064007500630074004E0061006D0065000000000046006F007400690061002E00530071006C0043006C00720000000000340008000100500072006F006400750063007400560065007200730069006F006E00000031002E0030002E0030002E003000000038000800010041007300730065006D0062006C0079002000560065007200730069006F006E00000031002E0030002E0030002E0030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000903000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
with permission_set = safe;
go

create function dbo.FormatString0(@format nvarchar(max), @arg0 sql_variant) returns nvarchar(max)
	as external name [Fotia.SqlClr].[Fotia.SqlClr.FormatString].FormatString0
go
create function dbo.FormatString1(@format nvarchar(max), @arg0 sql_variant, @arg1 sql_variant) returns nvarchar(max)
	as external name [Fotia.SqlClr].[Fotia.SqlClr.FormatString].FormatString1
go
create function dbo.FormatString2(@format nvarchar(max), @arg0 sql_variant, @arg1 sql_variant, @arg2 sql_variant) returns nvarchar(max)
	as external name [Fotia.SqlClr].[Fotia.SqlClr.FormatString].FormatString2
go
create function dbo.FormatString3(@format nvarchar(max), @arg0 sql_variant, @arg1 sql_variant, @arg2 sql_variant, @arg3 sql_variant) returns nvarchar(max)
	as external name [Fotia.SqlClr].[Fotia.SqlClr.FormatString].FormatString3
go
create function dbo.FormatStringMax0(@format nvarchar(max), @arg0 nvarchar(max)) returns nvarchar(max)
	as external name [Fotia.SqlClr].[Fotia.SqlClr.FormatStringMax].FormatStringMax0
go
create function dbo.FormatStringMax1(@format nvarchar(max), @arg0 nvarchar(max), @arg1 nvarchar(max)) returns nvarchar(max)
	as external name [Fotia.SqlClr].[Fotia.SqlClr.FormatStringMax].FormatStringMax1
go
create function dbo.FormatStringMax2(@format nvarchar(max), @arg0 nvarchar(max), @arg1 nvarchar(max), @arg2 nvarchar(max)) returns nvarchar(max)
	as external name [Fotia.SqlClr].[Fotia.SqlClr.FormatStringMax].FormatStringMax2
go
create function dbo.FormatStringMax3(@format nvarchar(max), @arg0 nvarchar(max), @arg1 nvarchar(max), @arg2 nvarchar(max), @arg3 nvarchar(max)) returns nvarchar(max)
	as external name [Fotia.SqlClr].[Fotia.SqlClr.FormatStringMax].FormatStringMax3
go